package com.skywolf.chem.common.sysconfig.utils;

/**
 * Created by pei_pei on 2020/10/27.
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

public final class TLBeanUtils {
    private static final Logger log = LoggerFactory.getLogger(TLBeanUtils.class);

    public TLBeanUtils() {
    }

    public static <T> List<T> copyList(List source, Class<T> targetClass) {
        if(CollectionUtils.isEmpty(source)) {
            return Collections.emptyList();
        } else {
            ArrayList targetList = new ArrayList(source.size());
            source.forEach((e) -> {
                try {
                    Object e1 = targetClass.newInstance();
                    BeanUtils.copyProperties(e, e1);
                    targetList.add(e1);
                } catch (Exception var4) {
                    log.error("TLBeanUtils.copyList错误", var4);
                    throw new RuntimeException("bean copy error!");
                }
            });
            return targetList;
        }
    }
}
